package com.laotou99.wmsjjj.wmsjjj.web;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.laotou99.wmsjjj.wmsjjj.bean.DemoInfo;
import com.laotou99.wmsjjj.wmsjjj.repository.DemoInfoRepository;
import com.laotou99.wmsjjj.wmsjjj.service.Test1Service;

@Controller
public class Test1Controller {
	
	@Autowired
	private DemoInfoRepository demoInfoRepository;
	
	@Autowired
	private Test1Service test1Service;

	@RequestMapping("/test1a")
	@ResponseBody
	public String test1a() {
		demoInfoRepository.save(new DemoInfo("aa", "bb"));
		demoInfoRepository.save(new DemoInfo("aa1", "bb2"));
		return "abc";
	}
	
	@RequestMapping("/test3a")
	@ResponseBody
	public String test3a() {
		test1Service.test1();	
		return "test3";
	}
	
	@RequestMapping("/test3") 
	public String test3(ModelMap map) {
		map.addAttribute("abc", "aa1a2aa");
		return "test3";
	}
	
	@RequestMapping("/test4a")
	public String test4a(ModelMap map) {
		System.out.println("test4");
		return "aaaa";
	} 
	
	@RequestMapping("/bbbba")
	public String test5a(ModelMap map) {
		System.out.println("test4");
		return "bbbb";
	}
	@RequestMapping("/getTest2a")
	@ResponseBody
	public Test1 test2a() {
		 
		Test1 t1 = new Test1("aaa","bbb","ccc",
			"eee","fff",1,2,3,4,5);
		
		return t1;
	}
	
	

	@RequestMapping("/productlist")
	public String productlist(ModelMap map){ 
		return "calendar";
	}

	@RequestMapping("/calendar")
	public String calendar(ModelMap map){ 
		return "calendar";
	}
	
	@RequestMapping("/quickmail")
	public String quickmail(ModelMap map){ 
		return "quickmail";
	}

	@RequestMapping("/todolist")
	public String todolist(ModelMap map){ 
		return "todolist";
	}
	
	@RequestMapping("/mainfooter")
	public String mainfooter(ModelMap map){ 
		return "mainfooter";
	}
	
	@RequestMapping("/mainheader")
	public String mainheader(ModelMap map){ 
		return "mainheader";
	}
	
	@RequestMapping("/leftside")
	public String leftside(ModelMap map){ 
		return "leftside";
	}
	
//	移动到IndexController	
//	@RequestMapping("/")
//	public String index(ModelMap map){ 
//		return "index";
//	}
//	@RequestMapping("/index")
//	public String index1(ModelMap map){ 
//		return "index";
//	}
	
	@RequestMapping("/starter")
	public String starter(ModelMap map){
		map.addAttribute("abc", "aaaaa");
		return "starter";
	}

	@RequestMapping("/index2")
	public String index2(ModelMap map){
		map.addAttribute("abc", "中文测试");
		return "index2";
	}
	
	@RequestMapping("/mailbox")
	public String mailBox(Model map){
		
		return "mailbox/mailbox";
	}
	
	@RequestMapping("/test1")
	public String test1(ModelMap map){ 
		map.addAttribute("abc", "中文测试"); 
		return "test1";
	}
	
	@RequestMapping("/test2")
	public String test2(ModelMap map){  
		map.addAttribute("abc", "中文测试"); 
		map.addAttribute("bbb", "efefesss"); 
		return "test2";
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping("/getData1")
	@ResponseBody
	public String getData1(ModelMap map){
		System.out.println("getData1()");
		List li1 = new ArrayList<>();
		for(int i1 = 0;i1<10;i1++){
			Map m2 = new HashMap<>();
			m2.put("Name", "aaa"+i1);
			m2.put("ParentName", "bbb"+i1);
			m2.put("Level", "ccc"+i1);
			m2.put("Desc", "ddd"+i1);
			li1.add(m2);
		}
		Map m3 = new HashMap<>();
		m3.put("total", li1.size());
		m3.put("rows", li1);
		return JSON.toJSONString(m3);
	}
	
	@SuppressWarnings({ "unchecked", "rawtypes" })
	@RequestMapping("/getData2")
	@ResponseBody
	public String getData2(ModelMap map,Model m,HttpServletRequest request){
		System.out.println("getData2()");
		System.out.println("map-=>"+JSON.toJSONString(map));
		System.out.println("m-=>"+JSON.toJSONString(m));
		
		String s1 = request.getParameter("abc");
		System.out.println("s1-=>"+JSON.toJSONString(s1));
		return JSON.toJSONString("abc");
	}
	
	@RequestMapping("/getData3")
	@ResponseBody
	public String getData3(ModelMap map,HttpServletRequest request){

		System.out.println("getData3()");
		String s1 = request.getParameter("abc");
		System.out.println("s1-=>"+JSON.toJSONString(s1));
		
		return JSON.toJSONString("eeffgg");
	}
	

	@RequestMapping("/temp1")
	public String temp1(ModelMap map){
		map.addAttribute("abc", "aaaaa");
		return "temp1";
	}
}

class Test1{
	private String aaa;
	private String bbb;
	private String ccc;
	private String eee;
	private String fff;
	
	private int iii1;
	private int iii2;
	private int iii3;
	private int iii4;
	private int iii5;
	
	
	
	public Test1(String aaa, String bbb, 
			String ccc, String eee, String fff, 
			int iii1, int iii2, int iii3, 
			int iii4,int iii5) 
	{
		super();
		this.aaa = aaa;
		this.bbb = bbb;
		this.ccc = ccc;
		this.eee = eee;
		this.fff = fff;
		this.iii1 = iii1;
		this.iii2 = iii2;
		this.iii3 = iii3;
		this.iii4 = iii4;
		this.iii5 = iii5;
	}
	public String getAaa() {
		return aaa;
	}
	public void setAaa(String aaa) {
		this.aaa = aaa;
	}
	public String getBbb() {
		return bbb;
	}
	public void setBbb(String bbb) {
		this.bbb = bbb;
	}
	public String getCcc() {
		return ccc;
	}
	public void setCcc(String ccc) {
		this.ccc = ccc;
	}
	public String getEee() {
		return eee;
	}
	public void setEee(String eee) {
		this.eee = eee;
	}
	public String getFff() {
		return fff;
	}
	public void setFff(String fff) {
		this.fff = fff;
	}
	public int getIii1() {
		return iii1;
	}
	public void setIii1(int iii1) {
		this.iii1 = iii1;
	}
	public int getIii2() {
		return iii2;
	}
	public void setIii2(int iii2) {
		this.iii2 = iii2;
	}
	public int getIii3() {
		return iii3;
	}
	public void setIii3(int iii3) {
		this.iii3 = iii3;
	}
	public int getIii4() {
		return iii4;
	}
	public void setIii4(int iii4) {
		this.iii4 = iii4;
	}
	public int getIii5() {
		return iii5;
	}
	public void setIii5(int iii5) {
		this.iii5 = iii5;
	}
	
	
}

/*

 
 
 */
